package com.siwei.mes.entity.experiment.fineAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 细骨料-表观密度
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FineAggregateJsldd {
    @ApiModelProperty(value = "单位")
    private String dw;
    @ApiModelProperty(value = "检测值")
    private String jcz;
    @ApiModelProperty(value = "标准值")
    private String bzz;
    @ApiModelProperty(value = "单项结论")
    private String dxjl;
    @ApiModelProperty(value = "备注")
    private String bz;
    @ApiModelProperty(value = "检测日期")
    private String jcrq;

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FineAggregateJsldd entity = new FineAggregateJsldd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FineAggregateJsldd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FineAggregateJsldd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FineAggregateJsldd entity = JsonUtils.getObject(objJson, FineAggregateJsldd.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getJcz()) || "null".equals(entity.getJcz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }
}
